{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "6e520417",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tensor(shape=[1, 1, 4, 4], dtype=Float32, value=\n",
       "[[[[ 0.00000000e+00,  1.00000000e+00,  2.00000000e+00,  3.00000000e+00],\n",
       "   [ 4.00000000e+00,  5.00000000e+00,  6.00000000e+00,  7.00000000e+00],\n",
       "   [ 8.00000000e+00,  9.00000000e+00,  1.00000000e+01,  1.10000000e+01],\n",
       "   [ 1.20000000e+01,  1.30000000e+01,  1.40000000e+01,  1.50000000e+01]]]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import mindspore\n",
    "import mindspore.ops as ops\n",
    "from mindspore.ops.operations.nn_ops import PSROIPooling\n",
    "from d2l import mindspore as d2l\n",
    "\n",
    "X = ops.arange(16, dtype=mindspore.float32).reshape(1, 1, 4, 4)\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "8beab150",
   "metadata": {},
   "outputs": [],
   "source": [
    "rois = mindspore.Tensor([[0, 0, 2, 2], [0, 1, 3, 3]], dtype=mindspore.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1618e091-3293-442a-8241-a9bddbf45619",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 0 1\n",
      "[[[0. 1.]\n",
      "  [4. 5.]]]\n",
      "0 1 1 2\n",
      "[[[1. 2.]\n",
      "  [5. 6.]]]\n",
      "1 2 0 1\n",
      "[[[4. 5.]\n",
      "  [8. 9.]]]\n",
      "1 2 1 2\n",
      "[[[ 5.  6.]\n",
      "  [ 9. 10.]]]\n",
      "0 1 0 1\n",
      "[[[4. 5.]\n",
      "  [8. 9.]]]\n",
      "0 1 2 3\n",
      "[[[ 6.  7.]\n",
      "  [10. 11.]]]\n",
      "1 2 0 1\n",
      "[[[ 8.  9.]\n",
      "  [12. 13.]]]\n",
      "1 2 2 3\n",
      "[[[10. 11.]\n",
      "  [14. 15.]]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[[[ 5.,  6.],\n",
       "         [ 9., 10.]]],\n",
       "\n",
       "\n",
       "       [[[ 9., 11.],\n",
       "         [13., 15.]]]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "roi_pooling = d2l.RoiPooling(mode='th', pool_size=(2,2))\n",
    "roi_pooling.get_pooled_rois(X, rois)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42ca981c-7497-420e-9bf0-8474c8b8091a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MindSpore",
   "language": "python",
   "name": "mindspore"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
